﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Xml;

namespace VoIPWeb
{
    public partial class CustomerInfor : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            get_all_infor();
        }

        #region Private Methods
        /// <summary>
        /// Hàm này lấy toàn bộ thông tin của customer và đổ lên lưới
        /// </summary>
        private void get_all_infor()
        {
            var v_str_user = Session["User"];
            var v_str_customer = Session["Customer"];
            var v_str_cpasswd = Session["Cpassword"];

            var v_str_api = string.Format("https://www.voipinfocenter.com/api/request.ashx?command=GetUserInfo&username={0}&password={1}&customer={2}", v_str_user, v_str_cpasswd, v_str_customer);

            HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(v_str_api);
            HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
            XmlDataDocument dataXML = new XmlDataDocument();

            dataXML.Load(HttpWResp.GetResponseStream());
            XmlNodeList v_xml_customer_nodelist = dataXML.SelectNodes("/GetUserInfo/Customer");
            XmlNodeList v_xml_balance_nodelist = dataXML.SelectNodes("/GetUserInfo/Balance");
            XmlNodeList v_xml_email_nodelist = dataXML.SelectNodes("/GetUserInfo/EmailAddress");
           if(v_xml_customer_nodelist.Count!=0)
               m_lbl_customer.Text = v_xml_customer_nodelist[0].InnerText;
            if(v_xml_email_nodelist.Count!=0)
                m_lbl_email.Text = v_xml_email_nodelist[0].InnerText;
            if(v_xml_balance_nodelist.Count!=0)
                m_lbl_balance.Text = string.Format(v_xml_balance_nodelist[0].InnerText);
            m_lbl_password.Text = Session["Cpassword"].ToString();
        }
        #endregion
    }
}